package com.esm.sm800.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ListView;
import android.widget.TextView;

import com.esm.sm800.R;
import com.esm.sm800.adapter.CcmxAdapter;
import com.esm.sm800.database.manager.WarehousingrecordCenter;

import java.util.ArrayList;
import java.util.List;

import zuo.biao.library.base.BaseActivity;
import zuo.biao.library.model.Entry;

//仓储明细
public class CcmxActivity extends BaseActivity implements View.OnClickListener {

    private final String TAG = "CcmxActivity";

    private ListView lv_hpcode;
    TextView tv_num;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_ccmx);
        findViewById(R.id.tv_back).setOnClickListener(this);
        findViewById(R.id.tv_clear).setOnClickListener(this);

        lv_hpcode = (ListView) findViewById(R.id.lv_hpcode);
        tv_num = (TextView) findViewById(R.id.tv_num);

        WarehousingrecordCenter.getInstance().warehousing_recordlist = WarehousingrecordCenter.getInstance().getWarehousing_recordlist();
        updateData();
    }


    void updateData() {
        setList(getList());
        tv_num.setText(getString(R.string.list_total) + "  " + demodataList.size());
    }

    private CcmxAdapter adapter;

    private void setList(List<Entry<Integer, String>> list) {
        if (list == null) {
            return;
        }
        if (adapter == null) {
            adapter = new CcmxAdapter(context);
            lv_hpcode.setAdapter(adapter);
        }
        adapter.refresh(list);
    }

    private List<Entry<Integer, String>> demodataList;

    protected List<Entry<Integer, String>> getList() {
        demodataList = new ArrayList<Entry<Integer, String>>();
        for (int i = 0; i < WarehousingrecordCenter.getInstance().warehousing_recordlist.size(); i++) {
            demodataList.add(new Entry<Integer, String>(i, ""));
        }
        return demodataList;
    }

    public static final int REFRESH_UI = 1101;
    Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == REFRESH_UI) {

            }
        }
    };

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.tv_clear:
                onClear();
                break;

            case R.id.tv_back:
                finish();
                break;
        }
    }

    private void onClear() {

    }


    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_OK) {
            return;
        }
    }


    @Override
    public void initView() {

    }

    @Override
    public void initData() {

    }

    @Override
    public void initEvent() {

    }
}
